package com.wx.timer;

import com.wx.service.WxCheckSignatureService;
import com.wx.service.impl.WxCheckSignatureServiceImpl;
import com.wx.utils.MessageUtil;
import com.wx.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author DKH
 * @version 1.0.0
 * @createTime 2022年08月22日 10:26:00
 */
@Component
@EnableScheduling
@EnableAsync
@Slf4j
public class SendTimer {

    @Autowired
    private MessageUtil messageUtil;

    @Autowired
    private StringUtil stringUtil;

    /**
     * 定时发送模板消息
     */
    @Async
    @Scheduled(fixedDelay = 10000)  //间隔10秒
//    @Scheduled(cron = "* * 7,22 * * *") //每天7点和22点分别执行一次
    public  void SendText(){
        WxCheckSignatureServiceImpl.concurrentHashMap.forEach((k,v) ->{
            Map<String, String> map = new HashMap<>();
            map.put("FromUserName",v);
            log.info("定时器开始，向{}发送模板消息,时间为{}", v,stringUtil.getNowTime());
            messageUtil.sendTemplateMsg(map);
        });
    }

}
